<?php
namespace App\Admin\Controllers\Reimburse;

use App\Models\Reimburse\ReimbursePaid;
use Encore\Admin\Controllers\AdminController;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Request;
class ApplyPaidController extends AdminController{

    public function update($id)
    {
        $name = Request::get('name');
        $value = trim(Request::get('value'));
        if(!is_numeric($value) || $value < 0)return response()->json(['status' => false, 'message' => '输入值有误']);
        try{
            DB::beginTransaction();
            $model = ReimbursePaid::query()->find($id);
            $model->{$name} = $value;
            $flag = $model->save();
            if($flag){
                DB::commit();
                return response()->json(['status' => true, 'message' => '操作成功！']);
            }else{
                DB::rollBack();
                return response()->json(['status' => false, 'message' => '操作失败']);
            }
        }catch (QueryException $qe){
            DB::rollBack();
            report($qe);
            return response()->json(['status' => false, 'message' => '操作失败！']);
        }catch (\Exception $e){
            DB::rollBack();
            report($e);
            return response()->json(['status' => false, 'message' => '系统异常！']);
        }
    }
}
